﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace Lilium.Web.Mvc.Security
{
    public class ActionAuthorizationEventArgs: EventArgs
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="area"></param>
        /// <param name="contoller"></param>
        /// <param name="action"></param>
        /// <param name="token"></param>
        /// <remarks>
        /// Area, controller and action will be overrided by corresponding parameters, all other values will be copied from <see cref="context"/>.
        /// Note than dictionary copies will be created, so modifying dictionaries will not affect original ones.
        /// </remarks>
        public ActionAuthorizationEventArgs(AuthorizationContext context, string area, string contoller, string action, string token)
        {
            if (context == null) throw new ArgumentNullException("context");

            m_Action = action;
            m_Area = area;
            m_Controller = contoller;
            m_RouteValues = new Dictionary<string, object>(context.RouteValues);
            m_Token = token;
            m_User = context.User;
            m_UserValues = new Dictionary<string, object>(context.UserValues);
        }

        #region public string Area

        private readonly string m_Area;

        public string Area
        {
            get
            {
                return m_Area;
            }
        }

        #endregion

        #region public string Action

        private readonly string m_Action;

        public string Action
        {
            get
            {
                return m_Action;
            }
        }

        #endregion

        #region public ICollection<string> AuthorizationMessages

        private readonly ICollection<string> m_AuthorizationMessages = new List<string>();

        public ICollection<string> AuthorizationMessages
        {
            get
            {
                return m_AuthorizationMessages;
            }
        }

        #endregion

        #region public string Controller

        private readonly string m_Controller;

        public string Controller
        {
            get
            {
                return m_Controller;
            }
        }

        #endregion

        #region public ActionTokenAuthorizationResult Result

        private ActionAuthorizationResult m_Result;

        public ActionAuthorizationResult Result
        {
            get { return m_Result; }
            set { m_Result = value; }
        }

        #endregion

        #region public IDictionary<string, object> RouteValues

        private readonly IDictionary<string, object> m_RouteValues;

        public IDictionary<string, object> RouteValues
        {
            get
            {
                return m_RouteValues;
            }
        }

        #endregion

        #region public string Token

        private readonly string m_Token;

        public string Token
        {
            get
            {
                return m_Token;
            }
        }

        #endregion

        #region public IPrincipal User

        private readonly IPrincipal m_User;

        public IPrincipal User
        {
            get
            {
                return m_User;
            }
        }

        #endregion

        #region public IDictionary<string, object> UserValues

        private readonly IDictionary<string, object> m_UserValues;

        public IDictionary<string, object> UserValues
        {
            get
            {
                return m_UserValues;
            }
        }

        #endregion
    }
}